/*
 * @Author: zwf 240970521@qq.com
 * @Date: 2023-07-15 17:24:23
 * @LastEditors: zwf 240970521@qq.com
 * @LastEditTime: 2023-08-02 01:14:51
 * @FilePath: /esp32_motor/i2c/i2c.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef I2C_H
#define I2C_H

#include "pin.h"
#include "driver/i2c.h"

typedef struct
{
    i2c_port_t i2cNum;
    int        addr;
    char      *buf;
    size_t     size;
} I2CPacket;

typedef struct
{
    int busNum;
    int (*write)(I2CPacket packet);
    int (*read)(I2CPacket packet);
    int (*readFromCmd)(i2c_port_t i2cNum, i2c_cmd_handle_t cmd);
} I2CDev;

/*i2c初始化*/
void I2C_init(void);
/*创建i2c*/
esp_err_t I2C_createDev(i2c_port_t busNum, int sda, int scl, int clk,
                         I2CDev **dev);
/*获取i2c*/
esp_err_t I2C_getDev(int busNum, int sda, int scl, int clk, I2CDev **dev);
/*删除i2c*/
void I2C_delDev(i2c_port_t busNum);

#endif
